﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using Model;

namespace Dal
{
  public  class Tuckdal
    {
        public static List<Tuck> GetTuckone()
        {
            string sqlest = "select top 3 * from Truck";
            List<Tuck> list = new List<Tuck>();
            SqlParameter[] pams = { };
            SqlDataReader reader = DBhelper.ExecuteReader(sqlest, System.Data.CommandType.Text, pams);
            while (reader.Read())
            {
                Tuck tr = new Tuck();
                tr.Number = reader["Number"].ToString();
                tr.BuyDate = Convert.ToDateTime(reader["BuyDate"].ToString());
                tr.Type = reader["Type"].ToString();
                tr.Tonnage = Convert.ToInt32(reader["Tonnage"].ToString());
                tr.FK_TeamID = Convert.ToInt32(reader["FK_TeamID"].ToString());
                tr.State = Convert.ToInt32(reader["State"].ToString());
                tr.Remark = reader["Remark"].ToString();
                tr.CheckInTime = Convert.ToDateTime(reader["CheckInTime"].ToString());
                tr.AlterTime = Convert.ToDateTime(reader["AlterTime"].ToString());

                list.Add(tr);
            }
            return list;
        }
        public static int DelectOne(string TruckID)
        {
            string sqlest = "Update Truck set IsDelete='1' where TruckID=@TruckID";
            SqlParameter[] paras = new SqlParameter[]
            {
                new SqlParameter("@TruckID",TruckID),

            };
            return DBhelper.ExecuteNonQuery(sqlest, paras);

        }

        public static Model.Tuck Ectonte(string TruckID)
        {
            string sqlest = "select * from Truck where TruckID=@TruckID";
            SqlParameter[] paras = new SqlParameter[]
            {
                new SqlParameter("@TruckID",TruckID),

            };
            SqlDataReader reader = DBhelper.ExecuteReader(sqlest, paras);
            if (reader.Read())
            {
                Tuck tt = new Tuck
                {
                    Number = reader["Number"].ToString(),
                    Type = reader["Type"].ToString(),
                    Length = reader["Length"].ToString(),
                    Tonnage = Convert.ToInt32(reader["Tonnage"]),
                    State = Convert.ToInt32(reader["State"]),
                    Remark = reader["Remark"].ToString(),


                };
                return tt;
            }
            return null;
        }
        public static int Ecttwo(Tuck tt)
        {
            string sqlect = "Update Truck set Number=@Number,Type=@Type,Length=@Length,Tonnage=@Tonnage,State=@State,Remark=@Remark where TruckID=@TruckID";
            SqlParameter[] paras = new SqlParameter[]
            {
                new SqlParameter("@Number",tt.Number),
                new SqlParameter("@Type",tt.Type),
                new SqlParameter("@Length",tt.Length),
                new SqlParameter("@Tonnage",tt.Tonnage),
                new SqlParameter("@State",tt.State),
                new SqlParameter("@Remark",tt.Remark),
                new SqlParameter("@TruckID",tt.TruckID),

            };
            return DBhelper.ExecuteNonQuery(sqlect, paras);
        }
    }
}
